package Leetcode.ArrayAndLinkedList.rotate189;

/**
 * 暴力解法
 * 一次旋转一格，旋转k次
 * 时间复杂度O(n*k)  非最优解法
 * 空间复杂度O(1)
 */
public class Solution {
    public void rotate(int[] nums, int k) {
        if (nums == null || k < 1) {
            return;
        }
        if (nums.length < 2) {
            return;
        }
       int count = 0;
        while(count != k) {
            int temp = nums[nums.length-1];
            for(int i = nums.length - 1; i > 0;i--) {
               nums[i] = nums[i - 1];
            }
            nums[0] = temp;
            count++;
        }
    }

    public static void main(String[] args) {
        int[] nums = {1,2,3,4};
        Solution solution = new Solution();
        solution.rotate(nums,2);
        for(int i : nums) {
            System.out.print(i);
        }
    }
}
